package com.xju.admin.controller;

import com.xju.admin.entity.Section;
import com.xju.admin.service.SectionService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
public class SectionController {
    @Autowired
    private SectionService sectionService;

    @RequestMapping("section-list")
    public String sectionList(Model model){
        List<Section> sectionList=sectionService.findAll();
        model.addAttribute("sectionList",sectionList);
        return "module_one/section_list";
    }

    @RequestMapping("section-modify")
    public String modify(Section section){
        sectionService.modify(section);
        return "redirect:/section-list";
    }

    @RequestMapping("section-add")
    public String add(String secName,String secDescribe){
        sectionService.add(secName,secDescribe);
        return "redirect:/section-list";
    }

    @RequestMapping("section-add-page")
    public String addPage(){
        return "module_one/section_add";
    }

    @RequestMapping("section-delete")
    @ResponseBody
    public Object delete(String id){
        sectionService.delete(id);
        Map<String,Object> map=new HashMap<>();
        map.put("ok",true);
        return map;
    }
}
